package com.bkgy.modular.subjectQuery.service.impl;

import com.bkgy.modular.calsidata.entity.TbFalt;
import com.bkgy.modular.datacollect_bx.bean.JDataSave622;
import com.bkgy.modular.subjectQuery.entity.KeyValueEntity;
import com.bkgy.modular.subjectQuery.entity.ShareData;
import com.bkgy.modular.subjectQuery.service.RightDataTabService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName ColdRollingCurve2130Impl
 * @date 2023/1/12 14:10
 */
@Service("cold_curve2130")
public class ColdRollingCurve2130Impl implements RightDataTabService {
    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public ResultData findByRightData(Integer pageIndex, Integer pageSize, String coilId, String hotId, ShareData shareData) {
        Query query = new Query(Criteria.where("extid").is(coilId));
        List<TbFalt> tbFaltList = mongoTemplate.find(query, TbFalt.class);
        List<JDataSave622> jDataSave622List = mongoTemplate.find(query, JDataSave622.class);
        // 创建分页对象
        // PageHelper.startPage(pageIndex,pageSize);
        List<KeyValueEntity> mapList = new ArrayList<>();

        // tbFalt数据
        for (TbFalt tbFalt : tbFaltList) {
            String extid = tbFalt.getExtid();
            Map<String, Object> map = tbFalt.getEdge();
            for (String item : map.keySet()) {
                KeyValueEntity keyValueEntity = new KeyValueEntity();
                keyValueEntity.setKey(item);
                keyValueEntity.setValue(extid);
                mapList.add(keyValueEntity);
            }
        }

        // jDataSave622List数据
        for (JDataSave622 jDataSave622 : jDataSave622List) {
            String extid = jDataSave622.getExtid();
            Map<String, List<Double>> map = jDataSave622.getRow();
            for (String item : map.keySet()) {
                KeyValueEntity keyValueEntity = new KeyValueEntity();
                keyValueEntity.setKey(item);
                keyValueEntity.setValue(extid);
                mapList.add(keyValueEntity);
            }
        }
        // List<KeyValueEntity> lists = mapList.stream().skip((pageIndex - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        return ResultData.ResultDataSuccess(mapList,mapList.size());
    }
}
